package com.zrwl.poscloud.xo.mapper;

import com.zrwl.poscloud.base.entity.AdminRole;
import com.zrwl.poscloud.base.superI.SuperMapper;
import com.zrwl.poscloud.xo.vo.AdminRoleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 管理员权限管理 Mapper类
 *
 * @author 刘思童 AutoGenerate
 * @date 2021-04-22
 */
public interface AdminRoleMapper extends SuperMapper<AdminRole> {

    @Select(
            "<script>" +
                    " SELECT " +
                    "  a.uid, " +
                    "  a.status, " +
                    "  a.update_time      updateTime, " +
                    "  a.create_admin_uid createAdminUid, " +
                    "  l.role_name        roleName, " +
                    "  l.uid              roleUid, " +
                    "  c.user_name        name, " +
                    "  c.nick_name        nickName, " +
                    "  c.mobile, " +
                    "  d.nick_name        createAdminName " +
                    "  FROM " +
                    "  t_role l " +
                    "  LEFT JOIN t_admin_role_r a ON l.uid = a.role_uid AND a.admin_uid = #{param.adminUid}" +
                    "  LEFT JOIN t_role b ON a.role_uid = b.uid AND b.status = 1 " +
                    "  LEFT JOIN t_admin c ON a.admin_uid = c.uid AND c.status = 1 " +
                    "  LEFT JOIN t_admin d ON a.create_admin_uid = d.uid AND d.status = 1 " +
                    "  WHERE l.uid in ( " +
                    "  select role_uid from t_admin_role_r where admin_uid= #{meUid} and status=1 " +
                    ") " +
                    " order by a.create_time" +
                    "</script>"
    )
    List<AdminRoleVO> getadminRoleList(@Param("param") AdminRoleVO adminRoleVO, @Param("meUid") String meUid);

    @Select(
            "<script>" +
                    " SELECT a.uid,a.status,a.admin_uid adminUid,a.role_uid roleUid,a.create_admin_uid createAdminUid,b.nick_name nickName,b.status adminStatus,b.mobile" +
                    "  FROM t_admin_role_r a LEFT JOIN t_admin b ON a.admin_uid=b.uid" +
                    "  LEFT JOIN t_role c ON a.role_uid=c.uid AND c.status=1 AND c.is_super=1 " +
                    "  WHERE c.uid=#{param.roleUid}  AND b.status!=0" +
                    " order by a.create_time" +
                    "</script>"
    )
    List<AdminRoleVO> getSuperAdminRoleList(@Param("param") AdminRoleVO adminRoleVO);

    @Select(
            "<script>" +
                    "select  " +
                    "a.uid adminUid, " +
                    "o.uid roleUid, " +
                    "r.create_admin_uid, " +
                    "a.nick_name nickName, " +
                    "a.mobile, " +
                    "o.role_name " +
                    " from t_admin a  " +
                    "left join t_admin_role_r r on r.admin_uid=a.uid and r.status=1 " +
                    "left join t_role o on r.role_uid=o.uid   and r.status=1 " +
                    "where a.uid=#{param.adminUid}  " +
                    "order by r.create_time desc" +
                    "</script>"
    )
    List<AdminRoleVO> getMyFullRoleList(@Param("param") AdminRoleVO adminRoleVO);

    @Select(
            "<script>" +
                    " SELECT b.role_name roleName  " +
                    "  FROM t_admin_role_r a LEFT JOIN t_role b ON a.role_uid = b.uid" +
                    "  WHERE a.admin_uid=#{meUid} AND b.owner_uid=#{ownerUid}" +
                    "  order by a.create_time" +
                    "</script>"
    )
    List<AdminRoleVO> getComMerMatchRoleList(@Param("ownerUid") String ownerUid,@Param("meUid") String meUid);

}
